<?php

namespace api\modules\user\models;

use Yii;
use yii\data\ActiveDataProvider;
use common\models\user\UserAddress;

/**
 * This is the model class for table "{{%user_address}}".
 *
 * @property string $id
 * @property string $user_id 用户UID
 * @property string $name 收件人姓名
 * @property string $mobile 收件人手机号
 * @property string $province 省份
 * @property string $city 城市
 * @property string $district 区县
 * @property string $address_detail 详细地址
 * @property string $area_code 地区编码
 * @property string $postal_code 邮政编码
 * @property int $is_default 默认地址
 * @property string $created_at 地址添加时间
 * @property string $updated_at 最近更新时间
 */
class AddressSearch extends UserAddress {

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     * @return ActiveDataProvider
     */
    public function search($params = []) {
        $query = static::find();
        $query->where(['user_id' => Yii::$app->user->id]);

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        Yii::$app->db->cache(function ($db) use ($dataProvider) {
            $dataProvider->prepare();
        }, 60);

        return $dataProvider;
    }

}
